﻿//using System;
//using System.Collections.Generic;
//using System.ComponentModel;
//using System.Data;
//using System.Drawing;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using System.Windows.Forms;
//using Dapper.Contrib.Extensions;
//using Newtonsoft.Json.Linq;
//using pinduoduo.Model;
//using pinduoduo.Util;
//using RestSharp;
//using Tk.Soc.Share.Common.Helpers;

//namespace pinduoduo
//{
//    public partial class OrderFrom : Form
//    {
//        private List<GoodOrderViewModel> goodOrderViewModels = new List<GoodOrderViewModel>();
//        public OrderFrom()
//        {
//            InitializeComponent();
//            this.dataGridView1.AutoGenerateColumns = false;
//        }

//        private void button1_Click(object sender, EventArgs e)
//        {

//            //OrderModel orderModel = new OrderModel();
//            //this.dataGridView1.Rows.Clear();
//            //string goodId = this.goods_id.Text.Trim();
//            //string url = "http://mobile.yangkeduo.com/proxy/api/api/aristotle/order_list?";

//            //goodOrderViewModels.Clear();
//            //var tokens = DataBaseHelper.SqLiteDBCon.GetAll<PddToken>();

//            //foreach (var item in tokens)
//            //{
//            //    var restclient = new RestClient(url);

//            //    restclient.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64)";

//            //    //restclient.Proxy = RestClientUtil.CreateWebProxy("175.146.210.108:4256");
//            //    //restclient.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

//            //    var request = new RestRequest(Method.POST);
//            //    request.AddHeader("Content-Type", "application/x-www-form-urlencoded; Charset=UTF-8");
//            //    request.AddHeader("Accept", "application/json, text/javascript, */*");
//            //    request.AddHeader("Accept-Encoding", "gzip, deflate");
//            //    request.AddHeader("AccessToken", item.PDDAccessToken);
//            //    request.AddHeader("Host", "mobile.yangkeduo.com");
//            //    request.AddHeader("Referer", url);
//            //    request.AddCookie("PDDAccessToken", item.PDDAccessToken);

//            //    orderModel.GetOrderType(this.order_type.Text);
//            //    request.AddObject(orderModel);
//            //    var response = restclient.Execute(request);

//            //    try
//            //    {
//            //        if (!string.IsNullOrWhiteSpace(response.Content))
//            //        {
//            //            GoogOrder googOrder = JsonHelper.DeserializeObject<GoogOrder>(response.Content);
//            //            if (googOrder.orders == null || googOrder.orders.Count == 0)
//            //            {
//            //                continue;
//            //            }
//            //            foreach (var order in googOrder.orders)
//            //            {
//            //                if (order == null)
//            //                {
//            //                    continue;
//            //                }
//            //                if (order.order_goods.Count == 0)
//            //                {
//            //                    continue;
//            //                }
//            //                if (order.order_goods[0].goods_id != goodId)
//            //                {
//            //                    continue;
//            //                }
//            //                GoodOrderViewModel goodOrderViewModel = new GoodOrderViewModel();
//            //                goodOrderViewModel.MailId = order.mall.id;
//            //                goodOrderViewModel.Uid = item.pdd_user_id;
//            //                goodOrderViewModel.PDDAccessToken = item.PDDAccessToken;
//            //                goodOrderViewModel.MailName = order.mall.mall_name;
//            //                goodOrderViewModel.good_id = order.order_goods[0].goods_id;
//            //                goodOrderViewModel.goods_name = order.order_goods[0].goods_name;
//            //                goodOrderViewModel.order_sn = order.order_sn;

//            //                goodOrderViewModel.order_status = order.order_status_prompt;
//            //                goodOrderViewModels.Add(goodOrderViewModel);

//            //            }

//            //        }
//            //    }
//            //    catch
//            //    {
//            //    }
//            //}

//            //this.dataGridView1.DataSource = new BindingList<GoodOrderViewModel>(goodOrderViewModels);

//            //AutoSizeColumn(dataGridView1);
//            //string url = "http://api.yangkeduo.com/api/oakstc/v14/goods/" + goodId + "?goods_id=" + goodId + "&pdduid=" + pdd_user_id_cookie.Value;

//        }



//        private void OrderFrom_Load(object sender, EventArgs e)
//        {

//        }

//        /// <summary>
//        /// 全部收货
//        /// </summary>
//        /// <param name="sender"></param>
//        /// <param name="e"></param>
//        private async void button5_Click(object sender, EventArgs e)
//        {
//            foreach (DataGridViewRow item in this.dataGridView1.Rows)
//            {
//                GoodOrderViewModel goodOrderViewModel = item.DataBoundItem as GoodOrderViewModel;
//                if (goodOrderViewModel == null) { continue; }
//                if (!goodOrderViewModel.order_status.Contains("待收货"))
//                {
//                    continue;
//                }
//                string url = "http://apiv4.yangkeduo.com/order/" + goodOrderViewModel.order_sn + "/received?pdduid=" + goodOrderViewModel.Uid;

//                //string url = "http://mobile.yangkeduo.com/proxy/api/order/" + goodOrderViewModel.order_sn + "?pdduid=" + goodOrderViewModel.Uid;
//                var restclient = new RestClient(url);


//                restclient.UserAgent = "android Mozilla/5.0 (Linux; Android 5.1; OPPO R9tm Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.121 Mobile Safari/537.36";

//                var request = new RestRequest(Method.POST);
//                request.AddHeader("Content-Type", "application/json");
//                request.AddHeader("Accept", "application/json, text/javascript, */*");
//                request.AddHeader("Accept-Encoding", "gzip, deflate");
//                request.AddHeader("AccessToken", goodOrderViewModel.PDDAccessToken);
//                request.AddHeader("Host", "apiv4.yangkeduo.com");
//                request.AddHeader("Referer", url);
//                var response = await restclient.ExecuteAsync(request);
//                if (!string.IsNullOrWhiteSpace(response.Content) && response.Content.Contains("已确认收货，正在前往评价..."))
//                {
//                    this.richTextBox1.AppendText("订单：" + goodOrderViewModel.order_sn + "收获成功 \r\n");
//                }
//            }
//        }

//        /// <summary>
//        /// 一键评价
//        /// </summary>
//        /// <param name="sender"></param>
//        /// <param name="e"></param>
//        private async void button6_Click(object sender, EventArgs e)
//        {
//            foreach (DataGridViewRow item in this.dataGridView1.Rows)
//            {
//                GoodOrderViewModel goodOrderViewModel = item.DataBoundItem as GoodOrderViewModel;
//                if (goodOrderViewModel == null) { continue; }
//                if (!goodOrderViewModel.order_status.Contains("待评价"))
//                {
//                    continue;
//                }
//                Unrated unrated = new Unrated();
//                unrated.goods_id = goodOrderViewModel.good_id;
//                unrated.order_sn = goodOrderViewModel.order_sn;
//                unrated.anonymous = 0;
//                unrated.timeline_sync_type = 1;
//                unrated.comprehensive_dsr = 5;
//                unrated.anti_content = "";

//                string url = "http://mobile.yangkeduo.com/proxy/api/v2/order/goods/review?pdduid=" + goodOrderViewModel.Uid;

//                var restclient = new RestClient(url);


//                restclient.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1";

//                var request = new RestRequest(Method.POST);
//                request.AddHeader("Content-Type", "application/json");
//                request.AddHeader("Accept", "application/json, text/javascript, */*");
//                request.AddHeader("Accept-Encoding", "gzip, deflate");
//                request.AddHeader("AccessToken", goodOrderViewModel.PDDAccessToken);
//                request.AddHeader("Host", "mobile.yangkeduo.com");
//                request.AddHeader("Origin", "http://mobile.yangkeduo.com");
//                request.AddHeader("Referer", url);


//                request.AddJsonBody(unrated);

//                var response = await restclient.ExecuteAsync(request);
//                if (!string.IsNullOrWhiteSpace(response.Content))
//                {
//                    this.richTextBox1.AppendText("订单：" + goodOrderViewModel.order_sn + "五星好评成功 \r\n");
//                }
//            }
//        }

//        private void button3_Click(object sender, EventArgs e)
//        {

//            //foreach (DataGridViewRow item in this.dataGridView1.Rows)
//            //{
//            //    GoodOrderViewModel goodOrderViewModel = item.DataBoundItem as GoodOrderViewModel;

//            //    string url = "http://mobile.yangkeduo.com/proxy/api/order/" + goodOrderViewModel.order_sn + "?pdduid=" + goodOrderViewModel.Uid;
//            //    var restclient = new RestClient(url);


//            //    restclient.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36";

//            //    var request = new RestRequest(Method.POST);
//            //    request.AddHeader("Content-Type", "application/json");
//            //    request.AddHeader("Accept", "application/json, text/javascript, */*");
//            //    request.AddHeader("Accept-Encoding", "gzip, deflate");
//            //    request.AddHeader("AccessToken", goodOrderViewModel.PDDAccessToken);
//            //    request.AddHeader("Host", "mobile.yangkeduo.com");
//            //    request.AddHeader("Referer", url);
//            //    var response = await restclient.ExecuteAsync(request);
//            //}

//        }

//        /// <summary>
//        /// 查询物流状态
//        /// </summary>
//        /// <param name="sender"></param>
//        /// <param name="e"></param>
//        private async void button4_Click(object sender, EventArgs e)
//        {
//            foreach (GoodOrderViewModel goodOrderViewModel in goodOrderViewModels)
//            {
//                OrderStatus orderStatus = new OrderStatus();
//                orderStatus.ts = PddApi.GetPddTime();

//                if (goodOrderViewModel == null) { continue; }
//                string url = "http://mobile.yangkeduo.com/proxy/api/order/" + goodOrderViewModel.order_sn + "?pdduid=" + goodOrderViewModel.Uid;
//                var restclient = new RestClient(url);


//                restclient.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36";

//                var request = new RestRequest(Method.POST);
//                request.AddHeader("Content-Type", "application/json");
//                request.AddHeader("Accept", "application/json, text/javascript, */*");
//                request.AddHeader("Accept-Encoding", "gzip, deflate");
//                request.AddHeader("AccessToken", goodOrderViewModel.PDDAccessToken);
//                request.AddHeader("Host", "mobile.yangkeduo.com");
//                request.AddHeader("Referer", url);
//                request.AddHeader("Origin", "http://mobile.yangkeduo.com");

//                request.AddCookie("PDDAccessToken", goodOrderViewModel.PDDAccessToken);

//                var response = await restclient.ExecuteAsync(request);
//                if (string.IsNullOrWhiteSpace(response.Content))
//                {
//                    this.richTextBox1.AppendText("订单：" + goodOrderViewModel.order_sn + "获取物流信息失败 \r\n");
//                    continue;
//                }
//                var jo = JObject.Parse(response.Content);

//                var express_infoToken = jo.SelectToken("express_info");
//                if (express_infoToken != null)
//                {
//                    goodOrderViewModel.ExpressNumber = express_infoToken["tracking_number"].ToString();
//                    goodOrderViewModel.ExpressName = express_infoToken["shipping_name"].ToString();
//                    var traces = express_infoToken["traces"].ToArray();
//                    if (traces != null && traces.Length > 0)
//                    {
//                        var trace = traces.FirstOrDefault();
//                        string info = trace["info"].ToString();
//                        goodOrderViewModel.LogisticsStatus = info;
//                    }

//                }

//                //var order_desc_listArray = order_desc_listToken.ToArray();
//                // foreach (var order_desc_list in order_desc_listArray)
//                // {
//                //   string key =  order_desc_list["key"].ToString();
//                //     if (key == "物流公司") {
//                //         goodOrderViewModel.ExpressName = order_desc_list["value"].ToString();
//                //     }
//                //     if (key == "快递单号")
//                //     {
//                //         goodOrderViewModel.ExpressNumber = order_desc_list["value"].ToString();
//                //     }
//                // }
//            }
//            this.dataGridView1.DataSource = null;

//            this.dataGridView1.DataSource = new BindingList<GoodOrderViewModel>(goodOrderViewModels);
//        }

//        /// <summary>
//        /// 查询
//        /// </summary>
//        /// <param name="sender"></param>
//        /// <param name="e"></param>
//        private void button2_Click(object sender, EventArgs e)
//        {

//        }

//        private void button7_Click(object sender, EventArgs e)
//        {

//        }

//        private void button8_Click(object sender, EventArgs e)
//        {

//        }
//    }


  
//}
